package com.sunwayworld.baseline.framework.constant;

import com.sunwayworld.framework.exception.InvalidDataException;
import com.sunwayworld.framework.utils.ObjectUtils;

public enum StorageEngine {
    mongo("mongo", "mongo存储"),
    clickhouse("clickhouse", "clickhouse存储");

    public String db;
    public String dbDesc;

    StorageEngine(String db, String dbDesc) {
        this.db = db;
        this.dbDesc = dbDesc;
    }

    public static StorageEngine getEngine(StorageEngine bean) {
        if (ObjectUtils.isEmpty(bean.db)) {
            throw new InvalidDataException("status is null");
        }
        StorageEngine[] values = StorageEngine.values();
        for (StorageEngine s : values) {
            if (s.db.equals(bean.db)) {
                return s;
            }
        }
        throw new InvalidDataException("db not found:" + bean.db);
    }

    public String getDb() {
        return db;
    }

    public String getDbDesc() {
        return dbDesc;
    }
}
